; (function () {
    var input = document.getElementById('input')
    var output = document.getElementById('output')
    var optionsForm = document.getElementById('options')
    var turndownService = new window.TurndownService(options())

    input.addEventListener('input', update)

    optionsForm.addEventListener('change', function () {
        turndownService = new window.TurndownService(options())
        update()
    })

    update()

    function update() {
        output.value = turndownService.turndown(input.value)
    }

    function options() {
        var opts = {}
        var inputs = optionsForm.getElementsByTagName('select')
        for (var i = 0; i < inputs.length; i++) {
            var input = inputs[i]
            opts[input.name] = input.value
        }
        return opts
    }
})()